import Cookies from 'js-cookie'

const CookieKeys = {
  RefreshToken: '_zun_r_token',
  AccessToken: '_zun_a_token',
}

export interface TokenDB {
  SetToken(accessToken: string, refreshToken?: string): void
  GetAccessToken(): string
  GetRefreshToken(): string
}

export const db: TokenDB = {
  SetToken(accessToken: string, refreshToken?: string) {
    Cookies.set(CookieKeys.AccessToken, accessToken)
    if (refreshToken) Cookies.set(CookieKeys.RefreshToken, refreshToken)
  },
  GetAccessToken() {
    return Cookies.get(CookieKeys.AccessToken) || ''
  },
  GetRefreshToken() {
    return Cookies.get(CookieKeys.RefreshToken) || ''
  },
}

export default db
